package org.csu.mypetstorecmsapi.controller;

import org.csu.mypetstorecmsapi.common.BaseResponse;
import org.csu.mypetstorecmsapi.domain.Order;
import org.csu.mypetstorecmsapi.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrderController
{
    @Autowired
    private OrderService orderService;

    //获取order信息列表
    @GetMapping
    public BaseResponse<List<Order>> getOrders()
    {
        return BaseResponse.createForSuccess(orderService.getOrders());
    }

    //获取未处理order信息列表
    @GetMapping("/pending")
    public BaseResponse<List<Order>> getPendingOrders()
    {
        return BaseResponse.createForSuccess(orderService.getOrdersByStatus("P"));
    }

    //获取已处理order信息列表
    @GetMapping("solved")
    public BaseResponse<List<Order>> getSolvedOrders()
    {
        return BaseResponse.createForSuccess(orderService.getOrdersByStatus("S"));
    }

    //发货处理
    @PutMapping("/{id}")
    public BaseResponse<Void> deliver(@PathVariable int id)
    {
        orderService.setOrderStatus(id, "S");
        return BaseResponse.createForSuccess();
    }

    //删除
    @DeleteMapping("/{id}")
    public BaseResponse<Void> deleteOrder(@PathVariable int id)
    {
        orderService.deleteOrder(id);
        return BaseResponse.createForSuccess();
    }
}
